import 'package:flutter/material.dart';

import 'slide_transition_x.dart';

class AnimatedSwitcherRoute extends StatefulWidget {
  const AnimatedSwitcherRoute({super.key});

  @override
  State<AnimatedSwitcherRoute> createState() => _AnimatedSwitcherRouteState();
}

class _AnimatedSwitcherRouteState extends State<AnimatedSwitcherRoute> {
  int _count = 0;
  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      margin: EdgeInsets.all(30),
      height: 150,
      decoration: BoxDecoration(border: Border.all(color: Colors.red)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          AnimatedSwitcher(
            duration: Duration(milliseconds: 200),
            transitionBuilder: (Widget child, Animation<double> animation) {
              return SlideTransitionX(position: animation, child: child);
            },
            child: Text('$_count', key: ValueKey<int>(_count)),
          ),
          SizedBox(height: 30),
          ElevatedButton(
            onPressed: () {
              setState(() => _count += 1);
            },
            child: Text('+1'),
          ),
        ],
      ),
    );
  }
}
